package utils

import (
	"crypto/rand"
	"encoding/hex"
	"fmt"
	"time"
)

func GenerateSessionID() string {
	// 生成随机字节
	randomBytes := make([]byte, 16)
	rand.Read(randomBytes)

	// 组合时间戳和随机数
	timestamp := time.Now().UnixNano()
	return fmt.Sprintf("sess_%d_%s", timestamp, hex.EncodeToString(randomBytes))
}

func IsValidSessionID(sessionID string) bool {
	return len(sessionID) > 20 && sessionID[:5] == "sess_"
}
